

const Tf = [
    //设置位置//向量或者2个点
    function setPosition(v, p2) {
        if (p2 == undefined) {
            this.x = v?.x;
            this.y = v?.y;
        } else {
            this.x = v;
            this.y = p2;
        }
    },
    //向着V方向移动
    function move(v) {
        this.x += v.x;
        this.y += v.y;
    },
    ////向着V移动，移动到V的位置后停止
    function moveTo(v, speed = 1, coef) {
        onlyOneFn(speed)
        if (Vector.distance(this, v) <= 3) {
            this.x = v.x;
            this.y = v.y;
            return true
        }
        //方向
        v = new Vector(v.x - this.x, v.y - this.y)
        //单位1
        v = v.normal()
        if (coef != undefined) {
            //result = a + (b-a) * time
            // let  result =1 + (Transform.tep_speed -1) * coef
            Transform.tep_speed = Transform.tep_speed * coef
            //  
        }
        this.x += v.x * Transform.tep_speed;
        this.y += v.y * Transform.tep_speed;
       // console.log(this.x)
    }
    //  console.log(this.c)
]

let onlyOneFn = once(function (sp) {
    Transform.tep_speed = sp
    // console.log('once')
})
//只执行一次方法
function once(fn) {
    let caller = true;
    // console.log(caller)
    return function () {
        if (caller) {
            caller = false
            // console.log(caller)
            fn.apply(this, arguments)
        }
    }
}

//============================================================
export var Transform = (obj) => {
    Tf.forEach(function (f) {
        // console.log(f.name)
        obj[f.name] = f
    })
}

Transform(createjs.MovieClip.prototype)